package com.codeduck.service;

import com.codeduck.HealthCommonVar;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @date: 2023/2/5
 */
@Component
@Slf4j
public class HealthCheckJob {

    private static final String BAD = "bad";
    private static final String HEALTH = "health";
    @Resource
    private HealthCheckService healthCheckService;

    public void execute() {
        HealthCommonVar.setDbSafe(healthCheckService.dbMapperCheck() == 0 ? HEALTH : BAD);
        HealthCommonVar.setFsSafe(healthCheckService.fsCheck() == 0 ? HEALTH : BAD);
        log.info("QUARTZ: 磁盘状态[{}],数据源状态[{}]", HealthCommonVar.getFsSafe(), HealthCommonVar.getDbSafe());
    }
}
